package example.collections;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;

/**
 * Created by lenovo on 2016/11/7 0007.
 * Collection 和 ListIterator 类的 listIterator() 和 collection.reverse() 方法来反转集合中的元素
 */
public class Reverse {
    public static void main(String[] args) {
        String[] coins = {"A", "B", "C", "D", "E"};
        List<String> list = new ArrayList<String>();
//        for (String coin : coins) {
//            list.add(coin);
//        }
        Collections.addAll(list, coins);
        ListIterator<String> liter = list.listIterator();
        System.out.println("反转前");
        while (liter.hasNext()) {
            System.out.println(liter.next());
        }
        Collections.reverse(list);
        liter = list.listIterator();
        System.out.println("反转后");
        while (liter.hasNext()) {
            System.out.println(liter.next());
        }
    }
}
